// HSS.Forms.Design.TextControlDisplay.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       TextControlDisplay.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace HSS.Forms.Design
{

	/// <summary>
	/// TextControlDisplay
	/// </summary>
	internal sealed partial class TextControlDisplay : System.Windows.Forms.TextBox
	{

		/// <summary>
		/// Default Constructor
		/// </summary>
		public TextControlDisplay()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			SetStyle(ControlStyles.UserPaint, true);
			SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			SetStyle(ControlStyles.DoubleBuffer, true);
			SetStyle(ControlStyles.ResizeRedraw, true);
		}

		/// <summary>
		/// Specify the Trimming Format
		/// </summary>
		[DefaultValueAttribute(StringTrimming.EllipsisWord)]
		[DescriptionAttribute("The StringFormat Trimming Option to use.")]
		[CategoryAttribute("Appearance")]
		public StringTrimming TextTrimming
		{
			get { return _stringTrimming; }
			set
			{
				_stringTrimming = value;
				Invalidate();
			}
		} StringTrimming _stringTrimming = StringTrimming.EllipsisWord;

		/// <summary>
		/// Specify the Text Wrapping format
		/// </summary>
		[DefaultValueAttribute(StringFormatFlags.NoWrap)]
		[DescriptionAttribute("The StringFormat Wrapping Option to use.")]
		[CategoryAttribute("Appearance")]
		public StringFormatFlags TextWrapping
		{
			get { return _textWrapping; }
			set
			{
				_textWrapping = value;
				Invalidate();
			}
		} StringFormatFlags _textWrapping = StringFormatFlags.NoWrap;

		/// <summary>
		/// Gets or set the font of the text displayed by the control
		/// </summary>
		[Description("Gets or set the font of the text displayed by the control")]
		public override Font Font
		{
			get
			{
				return base.Font;
			}
			set
			{
				base.Font = value;
			}
		}


		/// <summary>
		/// OnPaint
		/// </summary>
		/// <param name="e">PaintEventArgs</param>
		[Description("Paint the text with clipping")]
		protected override void OnPaint(PaintEventArgs e)
		{

			RectangleF bounds = new RectangleF(0,
				this.DisplayRectangle.Y,
				this.DisplayRectangle.Width,
				this.DisplayRectangle.Height);

			StringFormat _format = new StringFormat();
			_format.FormatFlags = this.TextWrapping;
			_format.LineAlignment = StringAlignment.Center;
			_format.Trimming = this.TextTrimming;

			e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), bounds, _format);
		}

	}
}